package de.homelabs.hlmodules.cms.configuration.domain;

import java.util.ArrayList;
import java.util.List;

import de.homelabs.hlmodules.cms.api.template.service.IHLTemplateImportStrategy;

/**
 * The base configuration entity, gets loaded on spring bootstrap. Default is
 * set to filesystem strategy.
 * 
 * @author dmueller
 * 
 */
public class HLConfigurationEntity {
	// external needs a config path
	// default to internal(0)
	private int configType = 0;

	// where to find the files
	private String configPath = new String("");

	// Whether to use database or not, default not
	private boolean useDatabase = false;

	// default to Filesystem
	//private IHLTemplateImportStrategy importStrategy = new HLTemplateFileSystemLoadingStrategy();
	private IHLTemplateImportStrategy importStrategy = null;

	// indicates error on startup, application should not start
	private boolean hasErrors = false;

	// List of errors
	private List<String> errors = new ArrayList<String>();

	private String domain = new String("");
	
	/*************
	 * +***** getter / setter *
	 *******************/
	public int getConfigType() {
		return configType;
	}

	public void setConfigType(int configType) {
		this.configType = configType;
	}

	public String getConfigPath() {
		return configPath;
	}

	public void setConfigPath(String configPath) {
		this.configPath = configPath;
	}

	public boolean isUseDatabase() {
		return useDatabase;
	}

	public void setUseDatabase(boolean useDatabase) {
		this.useDatabase = useDatabase;
	}

	public boolean hasErrors() {
		return hasErrors;
	}

	public void setHasErrors(boolean hasErrors) {
		this.hasErrors = hasErrors;
	}

	public List<String> getErrors() {
		return this.errors;
	}

	public boolean addError(String message) {
		return this.errors.add(message);
	}

	public IHLTemplateImportStrategy getImportStrategy() {
		return importStrategy;
	}

	public void setImportStrategy(IHLTemplateImportStrategy importStrategy) {
		this.importStrategy = importStrategy;
	}
	
	/**
	 * setter for jndi
	 * 
	 * @param strategy
	 * @throws ClassNotFoundException
	 * @throws InstantiationException
	 * @throws IllegalAccessException
	 */
	public void setStrategy(String strategy) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
		Class<?> strategyClass = Class.forName(strategy);
		this.importStrategy = (IHLTemplateImportStrategy) strategyClass.newInstance();
	}

	public String getDomain() {
		return domain;
	}

	public void setDomain(String domain) {
		this.domain = domain;
	}
}
